Skip to content

fix: declare c2pa XML namespace on SVG root, not manifest tag#2113

Open
ak-singh wants to merge 2 commits into
contentauth:mainfrom
ak-singh:fix/svg-namespace-on-root
Open

fix: declare c2pa XML namespace on SVG root, not manifest tag#2113
ak-singh wants to merge 2 commits into
contentauth:mainfrom
ak-singh:fix/svg-namespace-on-root

Conversation

@ak-singh
Copy link
Copy Markdown

@ak-singh ak-singh commented May 3, 2026

Changes in this pull request

Issue

SVG signing was adding the xmlns:c2pa namespace to the <c2pa:manifest> element. Issue #1634 requests that it be declared on the root <svg> element instead.

Before this fix:

<svg xmlns="http://www.w3.org/2000/svg">
  <metadata>
    <c2pa:manifest xmlns:c2pa="http://c2pa.org/manifest">…base64…</c2pa:manifest>
  </metadata>
</svg>

After this fix:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:c2pa="http://c2pa.org/manifest">
  <metadata>
    <c2pa:manifest>…base64…</c2pa:manifest>
  </metadata>
</svg>

Fix

  • Adds xmlns:c2pa to the root <svg> element if not already present.
  • Stops adding xmlns:c2pa to new <c2pa:manifest> elements, since the root now has it.

Test

Modified three existing tests to assert the new namespace position: test_write_svg_no_meta, test_write_svg_with_meta, and test_write_svg_with_manifest.

Added two new tests:

  • test_write_svg_no_metadata_element — covers the Empty arm (sample5).
  • test_write_svg_namespace_idempotent — re-signs and asserts xmlns:c2pa isn't duplicated on the root.

Verified failing on main and passing with the fix.

Possible follow-ups

  • Stripping the inline xmlns:c2pa from <c2pa:manifest> when re-signing files that were already signed by older code. Handling this cleanly would require stripping just that attribute while leaving the element's other attributes untouched, which adds unnecessary complexity. The output is still valid XML, and this duplication will naturally decrease over time as more files are signed using the updated implementation. I can include this in the PR if needed.

  • Reducing duplication in write_cai. The SVG-root check shows up in all three match arms. I kept it inline for visibility, but can pull it into a helper here if preferred. I could also unify the three arms into a single-pass loop. That could go in this PR or a separate one.

Checklist

  • This PR represents a single feature, fix, or change.
  • All applicable changes have been documented.
  • Any TO DO items (or similar) have been entered as GitHub issues and the link to that issue has been included in a comment.

Closes #1634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SVG bug, C2PA Manifest namespace should be at SVG level

2 participants